import 'package:fluent_ui/fluent_ui.dart';

import '../../global_setting.dart';
import '../../model/setting_model.dart';

///应用数据模型
class AppViewModel extends ChangeNotifier {
  SettingModel? _setting;

  ///获取是否已登录
  Future<bool> isAuth() async {
    _setting ??= await globalSetting.loadLocal();
    return _setting?.isAuth ?? false;
  }

  //保存设置模型数据
  Future<bool> saveSettingModel(final SettingModel model) async {
    var isModify = false;
    if (_setting == null) {
      _setting = model;
      isModify = true;
    } else {
      isModify = _setting!.copy(model);
    }
    if (isModify) {
      //存储到本地缓存
      final ok = await globalSetting.saveLocal(_setting!);
      debugPrint('saveSettingModel(model:${model.toMap()})=>$ok');
      return ok;
    }
    return false;
  }
}
